﻿#include "stdafx.h"

//***********************************
// Constructor - Destructor 
//***********************************
CListDoVat::CListDoVat()
{
	this->_n = 0;
	//this->_n = 12;
	//this->_obj[0] = new CDoVat("Ao giap", 116, 280, 0, 0, _T("vong1\\aogiap.png"), 1);
	//this->_obj[1] = new CDoVat("Tien", 140, 402, 0, 0, _T("vong1\\tien.png"), 1);		
	//this->_obj[2] =  new CDoVat("Ban do", 368, 405, 0, 0, _T("vong1\\bando.png"), 1);
	//this->_obj[3] = new	 CDoVat("Cai khien", 406, 532, 0, 0, _T("vong1\\caikhien.png"), 1);
	//this->_obj[4] = new CDoVat("Con ran", 526, 328, 0, 0, _T("vong1\\conran.png"), 0);
	//this->_obj[5] = new CDoVat("Cung", 539, 429, 0, 0, _T("vong1\\cung.png"), 1);
	//this->_obj[6] = new CDoVat("Ten", 768, 27, 0, 0, _T("vong1\\ten.png"), 1);
	//this->_obj[7] = new CDoVat("Kiem", 779, 515, 0, 0, _T("vong1\\kiem.png"), 1);
	//this->_obj[8] = new CDoVat("Cay", 0, 219, 0, 0, _T("vong1\\cay1.png"), 0);
	//this->_obj[9] = new CDoVat("Cay", 770, 0, 0, 0, _T("vong1\\cay2.png"), 0);
	//this->_obj[10] = new CDoVat("Chuon chuon", 228, 354, 0, 0, _T("vong1\\chuonchuon.png"), 0);
	//this->_obj[11] = new CDoVat("Bar", 0, 620, 0, 0, _T("vong1\\bar.png"), 0);
}


CListDoVat::~CListDoVat()
{
	for(int i = 0; i < this->_n; i++)
	{
		delete this->_obj[i];
	}
}


//***********************************
//Getter - Setter
//***********************************
CDoVat* CListDoVat::GetDoVat(int x)
{
	return this->_obj[x];
}


int CListDoVat::N()
{
	return this->_n;
}


bool CListDoVat::N(int x)
{
	this->_n = x;
	return true;
}

//***********************************
// Functions
//***********************************
void CListDoVat::Insert(CDoVat* dv)
{
	this->_obj[this->_n++] = dv;
}


void CListDoVat::Draw(HDC hDC)
{
	for(int i = 0; i < this->_n; i++)
	{
		LPCTSTR filename = this->_obj[i]->FileName();
		int xSrc = this->_obj[i]->XSrc();
		int ySrc = this->_obj[i]->YSrc();

		this->_obj[i]->Load(filename);

		int w = this->_obj[i]->GetWidth();
		int h = this->_obj[i]->GetHeight();
		
		this->_obj[i]->TransparentBlt(hDC, xSrc, ySrc, w, h, RGB(33,33,33));

	}
}


void CListDoVat::DrawText(CDC* pDC, int sott, COLORREF txtColor, COLORREF bgColor)
{
	//sott: số thứ tự của đồ vật cần xuất text
	//txtColor: màu chữ
	//bgColor: màu nền
	if(this->_obj[sott]->Drawable())
	{
		pDC->SetTextColor(txtColor);
		pDC->SetBkColor(bgColor);

		int xsrc =  this->_obj[sott]->XSrc();
		int ysrc = this->_obj[sott]->YSrc();
		CString str = this->_obj[sott]->MoTa();

		//pDC->ExtTextOut(xsrc + 30, ysrc + 30, ETO_OPAQUE, CRect(xsrc + 20, ysrc + 20, xsrc + 10 * strLength, ysrc + 50), str, strLength, NULL);
		LOGFONT lf;
		::ZeroMemory(&lf,sizeof(lf));
		lf.lfHeight = 160;
		lstrcpy(lf.lfFaceName,_T("Verdana"));
		CFont font;
		font.CreatePointFontIndirect(&lf);
		CFont* pOldFone = pDC->SelectObject(&font);
		pDC->TextOutW(xsrc,ysrc,str);
		pDC->SelectObject(pOldFone);
	}
}



int CListDoVat::Check(CPoint point)
{
	//kiểm tra xem một điểm bất kỳ nào đó có thuộc vùng tọa độ hiển thị đồ vật không?
	int x = point.x;
	int y = point.y;
	for (int i = 0; i < this->_n; i++)
	{
		int xsrc = this->_obj[i]->XSrc();
		int ysrc = this->_obj[i]->YSrc();
		int w = this->_obj[i]->GetWidth();
		int h = this->_obj[i]->GetHeight();
		if ((x >= xsrc || x <= x + w) && (y >= ysrc || y <= y + ysrc))
			return i;
	}

	return -1;
}